package com.leesche.zcsp.node.utils;

import java.util.regex.Pattern;

public class RegexUtil {

	//正则表达式：验证用户名
    public static final String REGEX_USERNAME = "^[a-zA-Z]\\w{5,17}$";
 
    //正则表达式：验证手机号
    public static final String REGEX_MOBILE = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
 
    //正则表达式：验证邮箱
    public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
 
    //正则表达式：验证汉字
    public static final String REGEX_CHINESE = "^[\u4e00-\u9fa5],{0,}$";
 
    //正则表达式：验证中文字符
    public static final String REGEX_ID_CARD = "(^\\d{18}$)|(^\\d{15}$)";

    //正则表达式：验证URL地址
    public static final String REGEX_URL = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
 
    //正则表达式：验证IP
    public static final String REGEX_IP = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)";
 
    /**
     * @Title: isUsername 
     * @Description: TODO(校验用户名) 
     * @author 陈立勇 
     * @param username 用户名
     * @return true / false
     */
    public static boolean isUsername(String username) {
        return Pattern.matches(REGEX_USERNAME, username);
    }
 
    /**
     * @Title: isMobile 
     * @Description: TODO(校验手机号) 
     * @author 陈立勇 
     * @param mobile 手机号码
     * @return true / false
     */
    public static boolean isMobile(String mobile) {
        return Pattern.matches(REGEX_MOBILE, mobile);
    }
 
    /**
     * @Title: isEmail 
     * @Description: TODO(校验邮箱) 
     * @author 陈立勇 
     * @param email  邮箱
     * @return true / false
     */
    public static boolean isEmail(String email) {
        return Pattern.matches(REGEX_EMAIL, email);
    }
 
    /**
     * @Title: isChinese 
     * @Description: TODO(校验中文) 
     * @author 陈立勇 
     * @param chinese 中文字符串
     * @return true / false
     */
    public static boolean isChinese(String chinese) {
        return Pattern.matches(REGEX_CHINESE, chinese);
    }
 
    /**
     * @Title: isIDCard 
     * @Description: TODO(校验身份证号) 
     * @author 陈立勇 
     * @param idCard 身份证号
     * @return true / false
     */
    public static boolean isIDCard(String idCard) {
        return Pattern.matches(REGEX_ID_CARD, idCard);
    }
 
    /**
     * @Title: isUrl 
     * @Description: TODO(校验URL地址) 
     * @author 陈立勇 
     * @param url URL地址
     * @return true / false
     */
    public static boolean isUrl(String url) {
        return Pattern.matches(REGEX_URL, url);
    }

    /**
     * @Title: isIP
     * @Description: TODO(校验IP) 
     * @author 陈立勇 
     * @param ip
     * @return true / false
     */
    public static boolean isIP(String ip) {
        return Pattern.matches(REGEX_IP, ip);
    }
 
}